﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Servicios.Business.Modulo.Registro;
using Servicios.Business.Entidades;
using Servicios.Data.DataBases.Biblioteca;
using System.Data;


namespace UnitTest.Service.Data.Modulo.Registro
{
    /// <summary>
    /// Summary description for RegistroTU
    /// </summary>
    [TestClass]
    public class RegistroTU
    {
        public RegistroTU()
        {
            
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        /// <summary>
        /// Registro de Autor
        /// </summary>
        [TestMethod]
        public void TU_SD_003_01_RegistrarAutor()
        {
           RegistroDatos reg = new RegistroDatos();
            
            reg.Autor.Entity.Nombres = "Harvey";
            reg.Autor.Entity.Apellidos = "Deitel";
            reg.RegistrarAutor();

            Autor e = new Autor();
            Assert.IsNotNull(e.Entity.GetByID(reg.Autor.Entity.ID), "Objeto Editorial Nulo");
        }

        /// <summary>
        /// Registro de Editorial
        /// </summary>
        [TestMethod]
        public void TU_SD_003_04_RegistrarEditorial()
        {
            RegistroDatos reg = new RegistroDatos();
            reg.Editorial.Entity.Nombre = "Prentice Hall";
            reg.RegistrarEditorial();

            Editorial e = new Editorial();
            int idg = reg.Editorial.Entity.ID;
            Assert.IsNotNull(e.Entity.GetByID(idg),"Objeto Editorial Nulo " + idg);
            

        }


        /// <summary>
        /// Registro de 
        /// </summary>
        [TestMethod]
        public void TU_SD_003_04_RegistrarMaterialBibliografico()
        {
            TipoMaterialBibliografico tmb = new TipoMaterialBibliografico();
            var tmbRel =  tmb.Entity.GetByID(1);

            RegistroDatos reg = new RegistroDatos();
            reg.MaterialBibliografico.Entity.Titulo = "Cómo programar en C++";
            reg.MaterialBibliografico.Entity.AnioPublicacion = 2007;
            reg.MaterialBibliografico.Entity.Clasificacion = "R1 / D1 / R2";
            reg.MaterialBibliografico.Entity.Bib_TipoMaterialBibliografico = new TipoMaterialBibliograficoDTO().GetByID(1);
            

            reg.RegistrarMaterialBibliografico();
            MaterialBibliografico mb = new MaterialBibliografico();
            int idg = reg.MaterialBibliografico.Entity.ID;
            Assert.IsNotNull(mb.Entity.GetByID(idg), "Objeto Material Bibliográfico Nulo " + idg);
        }


        /// <summary>
        /// Registro de 
        /// </summary>
        [TestMethod]
        public void TU_SD_000_00_RegistroMaterialBibliografico()
        {
            RegistroDatos rd = new RegistroDatos();
            MaterialBibliografico mb = new MaterialBibliografico();
            mb.Entity.Titulo = "Cómo programar en C++";
            mb.Entity.AnioPublicacion = 2007;
            mb.Entity.Clasificacion = "R1 / D1 / R2";
            mb.Entity.Bib_TipoMaterialBibliograficoReference.EntityKey = new EntityKey("BibliotecaContext.Bib_TipoMaterialBibliografico", "ID", 1);
            rd.RegistrarMaterialBibliografico(mb);
        }


        /// <summary>
        /// Registro de 
        /// </summary>
        [TestMethod]
        public void TU_SD_003_04_RegistrarMaterialBibliografico_RAW()
        {
            using(BibliotecaContext bib = new BibliotecaContext())
            {
                var tmbRel = (from tmb in bib.TipoMaterialBibliograficoSet where tmb.ID == 1 select tmb).First();
                MaterialBibliografico mb = new MaterialBibliografico();
                mb.Entity.Titulo = "Cómo programar en C++";
                mb.Entity.AnioPublicacion = 2007;
                mb.Entity.Clasificacion = "R2 / D2 / R2";
                mb.Entity.Bib_TipoMaterialBibliografico = tmbRel;

                bib.AddToMaterialBibliograficoSet(mb.Entity);
                bib.SaveChanges();
                int idg = mb.Entity.ID;
                Assert.IsNotNull(mb.Entity.GetByID(idg), "Objeto Material Bibliográfico Nulo " + idg);
                
            }
        }

        
    }
}
